package org.blogwu.learn.multithread.chapter3.demo14;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 此处会吞掉异常.
 *
 * @author hyf
 * @date 2018-10-04
 **/
public class MainV2 implements Runnable {

    private int i;

    public MainV2(int i) {
        this.i = i;
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + " " + i + " start");
        i = 20 / i;
    }

    public static void main(String[] args) throws InterruptedException {
        System.out.println(Runtime.getRuntime().availableProcessors());
        ArrayBlockingQueue arrayBlockingQueue = new ArrayBlockingQueue(100);
        ThreadPoolExecutor th = new ThreadPoolExecutor(10, 20, 5, TimeUnit.SECONDS, arrayBlockingQueue);
        int i = 50;
        while (i >= 0) {
            MainV2 main = new MainV2(i);
            i--;
            th.execute(main);
        }
        th.shutdown();
        System.out.println("hello");
    }
}
